

use "$data/survey1_clean.dta", clear

global control male age_* log_inc log_inc_sq highschool college working student democrat republican 


   *** Worries***

loc experiments "z_worry_corona_econ z_worry_perecon"
		   
			   
preserve 

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""

global output_coeff ""
global output_se ""
global output_name""

foreach choice in `experiments' {

/* Statistics */

	
 xi:  reg `choice' highmort  , vce(r)
 
 	global `choice'_coeff =_b[highmort]
	global `choice'_se =_se[highmort]
	global output_name "$output_name a`choice' "
	global output_coeff "$output_coeff $`choice'_coeff "
	global output_se "$output_se $`choice'_se" 
 
 
    sigstar highmort, prec(4)
    estadd loc thisstat3 = "`r(bstar)'": col`colnum'
    estadd loc thisstat4 = "`r(sestar)'": col`colnum'
	
	

    estadd loc thisstat6 =  string(`e(r2)', "%9.2f"): col`colnum'
	qui sum `choice'_update  
	estadd loc thisstat7 =  r(N): col`colnum'


 xi:  reg `choice'_update  contagiontreatment `choice' , vce(r)
 
  	global `choice'_coeff =_b[contagiontreatment]
	global `choice'_se =_se[contagiontreatment]
	global output_name "$output_name b`choice' "
	global output_coeff "$output_coeff $`choice'_coeff "
	global output_se "$output_se $`choice'_se" 
 
    sigstar contagiontreatment, prec(4)
    estadd loc thisstat9 = "`r(bstar)'": col`colnum'
    estadd loc thisstat10 = "`r(sestar)'": col`colnum'


    estadd loc thisstat12 =  string(`e(r2)', "%9.2f"): col`colnum'
	qui sum `choice'_update  
	estadd loc thisstat13 =  r(N): col`colnum'




	
 xi:  reg `choice' highmort $control , vce(r)
 
 
    sigstar highmort, prec(4)
    estadd loc thisstat17 = "`r(bstar)'": col`colnum'
    estadd loc thisstat18 = "`r(sestar)'": col`colnum'
	
		
    estadd loc thisstat20=  string(`e(r2)', "%9.2f"): col`colnum'
	qui sum `choice' 
	estadd loc thisstat21 =  r(N): col`colnum'



 xi:  reg `choice'_update  contagiontreatment `choice' $control, vce(r)
 
    sigstar contagiontreatment, prec(4)
    estadd loc thisstat23 = "`r(bstar)'": col`colnum'
    estadd loc thisstat24 = "`r(sestar)'": col`colnum'

    estadd loc thisstat26 =  string(`e(r2)', "%9.2f"): col`colnum'
	qui sum `choice'_update  
	estadd loc thisstat27 =  r(N): col`colnum'

	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

	} 
	

	

loc rowlabels " "{\bf Panel A: No control variables}" " "  "High relative mortality" " "  " " "\midrule R$^2$" " Number of Observations " "\midrule"  "Contagion information" " " " " "\midrule R$^2$" " Number of Observations " "\midrule"  "{\bf Panel B: Including control variables}" " " "High relative mortality" " "  " " "\midrule R$^2$" " Number of Observations " "\midrule"  "Contagion information" " " " " "\midrule R$^2$" " Number of Observations " "\bottomrule""


loc rowstats ""

forval i = 1/27 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "$tables/experiment_mainpart2_combined.tex", replace cells(none) booktabs nonotes compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
   mtitle("US Economy" "Pers. Economic Sit."  ) ///
   mgroups("Worry about (standardized)" ,  pattern(1 0  1 0   ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

clear
 di $output_coeff

set obs 4
gen name_var = " "
gen coeff =" "
local l =1
foreach x in $output_name {
replace name_var = "`x'" in `l'
local ++l
}

local l =1
foreach x in $output_coeff {
replace coeff = "`x'" in `l'
local ++l
}

gen se =""
local l =1
foreach x in $output_se {
replace se = "`x'" in `l'
local ++l
}
destring se coeff, replace

gen uci = coeff+1.96*se
gen lci =coeff-1.96*se

sort name_var, stable // Right order for figure

export delimited using "$tables/tables_raw/table1_raw.csv", replace

